package com.wang.mandkey.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.wang.mandkey.App;
import com.wang.mandkey.R;
import com.wang.mandkey.tool.GlobalTool;
import com.wang.mandkey.utils.ProjectEnvironment;
import com.wang.mandkey.utils.SharePersistent;
import com.wang.mandkey.utils.StringUtils;
import com.waps.AppConnect;

public class WelComeActivity extends BaseActivity {

	private Button mButtonAgree, mButtonNegative;
	private String tag = "WelComeActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		  
		Intent i=getIntent();
		int flag=i.getIntExtra("flag", -1);
		if(0==flag){
			App.getInstance().doExit();
			finish();
			return;
		}
		
		new Handler().post(new Runnable() {
			@Override
			public void run() {
				try {
					AppConnect.getInstance(WelComeActivity.this);// 初始化广告
				} catch (Exception e) {
					e.printStackTrace();
					Log.i(tag, e.getMessage());
				}
			}
		});

		String keyeui = SharePersistent.getPerference(this,
				ProjectEnvironment.STRING_KEY_EUI);
		if (!StringUtils.isEmptyNull(keyeui)
				&& ProjectEnvironment.STRING_VALUE_EUI.equals(keyeui)) {
			GlobalTool.startOtherActivity(WelComeActivity.this,
					MainActivity.class);
		} else {
			initView();
		}

	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	void initView() {
		setContentView(R.layout.eui);
		mButtonAgree = (Button) findViewById(R.id.buttonAgree);
		mButtonAgree.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				SharePersistent.savePerference(WelComeActivity.this,
						ProjectEnvironment.STRING_KEY_EUI,
						ProjectEnvironment.STRING_VALUE_EUI);

				GlobalTool.startOtherActivity(WelComeActivity.this,
						MainActivity.class);
			}
		});
		mButtonNegative = (Button) findViewById(R.id.buttonNegative);
		mButtonNegative.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				App.exitApp(WelComeActivity.this);
			}
		});
	}
}
